/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package com.mcx.modules.generation.rest;

import com.mcx.exception.handler.ApiSuccess;
import com.mcx.modules.generation.domain.Gameserver;
import com.mcx.modules.generation.service.GameserverService;
import com.mcx.modules.generation.service.dto.GameserverQueryCriteria;
import org.springframework.data.domain.Pageable;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Sort;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.*;

/**
* @website https://el-admin.vip
* @author mcx
* @date 2022-03-18
**/
@RestController
@RequiredArgsConstructor
@Api(tags = "gameserver管理")
@RequestMapping("/api/gameserver")
public class GameserverController {

    private final GameserverService gameserverService;

    @GetMapping
    @ApiOperation("查询gameserver")
    public ResponseEntity<Object> queryGameserver(GameserverQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(gameserverService.queryAll(criteria,pageable),HttpStatus.OK);
    }

    @PostMapping
    @ApiOperation("新增gameserver")
    public ResponseEntity<Object> createGameserver(@Validated @RequestBody Gameserver resources){
        return new ResponseEntity<>(gameserverService.create(resources),HttpStatus.CREATED);
    }

    @PutMapping
    @ApiOperation("修改gameserver")
    public ResponseEntity<Object> updateGameserver(@Validated @RequestBody Gameserver resources){
        gameserverService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    @ApiOperation("删除gameserver")
    public ResponseEntity<Object> deleteGameserver(@RequestBody Integer[] ids) {
        gameserverService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @GetMapping("/get")
    public ResponseEntity<Object> gameServerPage(Integer id){
        if (id==null || id == 0) id = gameserverService.getCount();
        return new ResponseEntity<>(ApiSuccess.response(gameserverService.findById(id), "获取区服信息成功", HttpStatus.OK), HttpStatus.OK);
    }
}